package com.problem.leetcode;

import java.util.Arrays;

public class Problem219 {
    public static void main(String[] args) {
        new Problem219().containsNearbyDuplicate(new int[]{-1, -1}, 1);
    }

    public boolean containsNearbyDuplicate(int[] nums, int k) {
        if (nums == null || nums.length == 1) {
            return false;
        }

        Arrays.sort(nums);
        int begin = 0, end = nums.length - 1;
        while (begin < end) {
            if (nums[begin] + nums[end] < k) {
                ++begin;
            }

            if (nums[begin] + nums[end] > k) {
                --end;
            }

            if (nums[begin] + nums[end] == k) {
                return true;
            }
        }
        return false;
    }

}
